﻿@{
    ViewBag.Title = "ReportPublish";
    Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
@section head {
    @if (false)
    {<script src="~/Scripts/jquery-1.6.4-vsdoc.js" type="text/javascript"></script>}
    <link href="@Url.Content("~/Content/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.ztree.all-3.0.min.js")" type="text/javascript"></script>
    @Html.Partial("_JqGrid")
    <script language="javascript" type="text/javascript">
        var selectId = "";
        var gridId = "#tableId";
        var treeObj;
        $(document).ready(function () {
            //loadOrganization(true); //checkenable 节点前有复选框
            funGridInit();
        });
        function zTreeOnClick(event, treeId, treeNode, clickFlag) {
            curSelectNode = treeNode;
            selectId = treeNode.organization_id;
            $(gridId).trigger("reloadGrid");
        }
        function zTreeMenuCheck(event, treeId, treeNode) {
            //            if (treeNode.checked && treeNode.getParentNode() != null) {//当勾选节点时，同是勾选父节点本身。
            //                //只勾选父节点本身，无任何勾选联动操，触发 beforeCheck & onCheck 事件回调函数，这样可以自动勾选父节点的父节点。
            //                treeObj.checkNode(treeNode.getParentNode(), true, false, true); 
            //            }
        }
        function zTreeOnAsyncSuccess(event, treeId, treeNode) {
            treeObj = $.fn.zTree.getZTreeObj(treeId);
        }
        function Search() {
            //查询
            $(gridId).setGridParam({ page: 1 });
            $(gridId).trigger("reloadGrid");
        }
        function funReportPublish() {
            //数据下发
            //if (treeObj == null) return;
            //不按单位进行下发，改成按年度进行下发
            //            var nodes = treeObj.getCheckedNodes(true);
            //            if (nodes.length == 0) {
            //                parent.asyncbox.alert('请选择要下发的单位!', '提示');
            //                return;
            //            }
            //==========================================
            var selIds = jqGridHelper.getSelRowsData(gridId, "Report_ID");
            if (selIds == null || selIds == "") {
                parent.asyncbox.alert('请选择要下发的报表!', '提示');
                return;
            }
            if (selIds.split(',').length > 1) {
                parent.asyncbox.alert('只能选择一个报表进行下发!', '提示');
                return
            }
            //            var OrgIds = "";
            //            for (var i = 0; i < nodes.length; i++) {
            //                OrgIds += nodes[i].ID + ",";
            //            }
            //            if (OrgIds.length > 0)
            //                OrgIds = OrgIds.substring(0, OrgIds.length - 1); //把最后一个逗号去掉
            //
            var u = "/SystemManage/SubmitInfo/ChooseDate?ReprotId=" + selIds;
            parent.asyncbox.open({
                url: u,
                data: '',
                title: "选择发布日期",
                width: 300,
                height: 200,
                scroll: 'no',
                modal: true,
                btnsbar: parent.$.btn.OKCANCEL, //按钮栏配置请参考 “辅助函数” 中的 $.btn。
                callback: function (action, opener) {
                    if (action == 'ok') {
                        //alert(opener.document.getElementById("aa").value);
                        var nian = opener.document.getElementById("Year").value;
                        var yue = opener.document.getElementById("Month").value;
                        var jd = opener.document.getElementById("JD").value;
                        //
                        parent.showloading();
                        //$.post("/SystemManage/SubmitInfo/SetReportPublish/", { OrgId: OrgIds, ReportId: selIds, sYear: nian, sMonth: yue, sJd: jd }, function (d) {
                        $.post("/SystemManage/SubmitInfo/SetReportPublish/", { ReportId: selIds, sYear: nian }, function (d) {
                            if (d == "" || d == null) {
                                parent.hideloading();
                                parent.asyncbox.alert('下发成功!', '提示');
                            }
                            else {
                                alert(d);
                            }
                        });
                        //
                    }
                    if (action == 'cancel') {
                        return;
                    }
                }
            });
        }
        function funGridInit() {
            //初始化表格
            var option = {
                height: $("#divGridContainer").height() - 51,
                width: $("#divGridContainer").width() - 2,
                url: '@Url.Content("~/SystemManage/SubmitInfo/GetReportPublishList")',
                autowidth: false,
                datatype: "json",
                multiselect: true,
                sortname: 'Report_ID',
                sortorder: 'desc',
                colModel: [
                { label: '报表ID', name: 'Report_ID', width: 100 },
                { label: '报表名称', name: 'Report_Name', width: 300 },
                { label: '报表周期', name: 'Report_Cycle', width: 100, align: "center", formatter: 'select', editoptions: { value: "01:月报;02:季报;03:年报"} },
                { label: 'Web格式化', name: 'Report_IsWeb', width: 100, align: "center", formatter: 'select', editoptions: { value: "0:否;1:是"} },
                { label: '创建时间', name: 'Report_CreateDate', width: 100 },
                { label: '修改时间', name: 'Report_NewDate', width: 100 },
   	            ],
                onSelectRow: function (rowid, cellname, value, iRow, iCol) {
                    selectId = $(gridId).getCell(rowid, "Report_ID");
                },
                ondblClickRow: function (rowid) {
                },
                beforeRequest: function (d) {
                    // $(gridId).jqGrid('setGridParam', { postData: data });
                }
            };
            var o = jqGridHelper.getConfig("#pageId", option);
            $(gridId).jqGrid(o);
        }
    </script>
    }
    <!--头部导航,不用时可以去掉-->
    <div class="ui-layout-north">
        <div id="headertitle">
        </div>
        <div class="buttonlist" style="float: right; height: 34px; line-height: 36px; margin-right: 20px;">
            <a onclick="funReportPublish()" class="button green"><span class="icon-botton" style="background: url('/Content/16/report_go.png') no-repeat scroll 0px 4px;">
            </span>报表下发</a>
        </div>
    </div>
    <!--左侧导航，不用时直接去掉-->
    @*<div class="ui-layout-west">
    @Html.Partial("_OrganizationCheckTree")
</div>*@
    <!--主窗体，页面都需要的div-->
<div id="divGridContainer" class="ui-layout-center" style="overflow: auto;">
    <table id="tableId">
    </table>
    <div id="pageId">
    </div>
</div>
